{extend name="public:_index" /}
{block name="title"}菜单管理{/block}
{block name="description"}描述{/block}
{block name="keywords"}关键词{/block}
{block name="plugins_css"}
    <link href="/static/back/plugins/forms/togglebutton/toggle-buttons.css" type="text/css" rel="stylesheet" />
{/block}
{block name="heading"}菜单{/block}
{block name="breadcrumb"}菜单{/block}
{block name="wrapper"}
<div class="col-lg-12">
    <div class="">
        <button class="btn btn-default" onclick="menu_add('添加', '{:url('back/Menu/add')}', '600', '500');">
            <span class="icon16 entypo-icon-plus-2"></span>
            添加菜单
        </button>
        <div class="marginB10"></div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4>
                <span class="icon16 icomoon-icon-numbered-list"></span>
                <span>菜单列表</span>
            </h4>
            <a href="#" class="minimize" style="display: none;">Minimize</a>
        </div>
        <div class="panel-body noPad">
            <div class="responsive" tabindex="5005" style="overflow: hidden; outline: none;">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>名称</th>
                        <th>Url</th>
                        <th>排序</th>
                        <th>是否显示</th>
                        <th>作者</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="menus" id="vo"}

                    <tr>
                        <td>{$vo.id}</td>
                        <td style="text-align:left;">{$vo._name}</td>
                        <td>{$vo.url}</td>
                        <td>{$vo.sort_number}</td>
                        <td>
                            <div class="center marginR10">
                                <div class="iToggle-button">
                                    <input type="checkbox" class="nostyle" data-id="{$vo.id}" {$vo.is_show?'checked="checked"':''} >
                                </div>
                            </div>
                        </td>
                        <td>{$vo.user.nickname}</td>
                        <td>
                            <div class="controls center">
                                <a href="javascript:void(0);" class="tip" onclick="menu_edit('编辑', '{$vo.id|url='back/Menu/edit',['id'=>###]}', '600', '500');"  oldtitle="Edit task" title="编辑" data-hasqtip="true">
                                    <span class="icon12 icomoon-icon-pencil"></span>
                                </a>
                                <a href="javascript:void(0);" class="tip" onclick="menu_del(this, '{$vo.id}')" oldtitle="Remove task" title="删除" data-hasqtip="true">
                                    <span class="icon12 icomoon-icon-remove"></span>
                                </a>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
        </div>
    </div><!-- End .panel -->
</div>
{/block}

{block name="plugins_js"}

<script type="text/javascript" src="/static/back/js/common.js"></script>
<script type="text/javascript" src="/static/back/plugins/layer/layer.js"></script>
<script type="text/javascript" src="/static/back/plugins/forms/togglebutton/jquery.toggle.buttons.js"></script>

<script>
    /**
     * 添加菜单
     * @param title
     * @param url
     * @param w
     * @param h
     */
    function menu_add(title, url, w, h){
        layer_show(title, url, w, h);
    }

    /**
     * 编辑菜单
     * @param title
     * @param url
     * @param w
     * @param h
     */
    function menu_edit(title, url, w, h){
        layer_show(title, url, w, h);
    }

    /**
     * 删除菜单
     * @param obj
     * @param id
     */
    function menu_del(obj, id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                data: {
                    id: id
                },
                url: '/admin/menu/delete.html',
                dataType: 'json',
                success: function(response){
                    if (response.status == 'success') {
                        $(obj).parents("tr").remove();
                        layer.msg('删除成功!',{icon:1,time:1000});
                    } else if ( response.status == 'failed') {
                        layer.msg('删除失败', {icon:2,time:1000});
                    }
                },
                error:function(data) {
                    layer.msg('请求失败!',{icon:2,time:1000});
                    console.log(data.msg);
                },
            });
        });
    }
</script>

<script>
    $(document).ready(function() {
        $('.iToggle-button').toggleButtons({
            width: 70,
            label: {
                enabled: "<span class='icon16 icomoon-icon-checkmark white'></span>",
                disabled: "<span class='icon16 icomoon-icon-close white marginL10'></span>"
            }
        });

        /**
         * 更改状态
         */
        $('.iToggle-button input').change(function(){
            var is_show = $(this)[0].checked ? 1 : 0;
            $.ajax({
                type: 'POST',
                data: {
                    id: $(this).data('id'),
                    is_show: is_show
                },
                url: '/admin/menu/change_show.html',
                dataType: 'json',
                success: function(response){
                    if (response.status == 'success') {
                        layer.msg('修改成功!',{icon:1,time:1000});
                    } else if ( response.status == 'failed') {
                        layer.msg('修改失败', {icon:2,time:1000});
                    }
                },
                error:function(data) {
                    layer.msg('请求失败!',{icon:2,time:1000});
                    console.log(data.msg);
                },
            });
        });

    });

</script>

{/block}